<?php
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=訂單資料.xls");
$start = 1; 
?>
<?php if(is_array($dataarray)){foreach($dataarray as $value){?>
<?php if($start ==1) {?>
  <table widtd="100%" align="center"  border="1" cellpadding="3" cellspacing="1" class="table_style">
    <tr>
      <td>訂單代號</td>
      <td>訂單編號</td>
      <td>團購代號</td>
      <td>團購項目</td>
      <td>訂單金額</td>
      <td>付款方式</td>
      <td>下單日期</td>
      <td>會員代號</td>
      <td>會員名稱</td>
      <td>運費</td>
      <td>大小</td>
      <td>收件人</td>
      <td>郵遞區號</td>
      <td>地址</td>
      <td>電話</td>
      <td>收貨時間</td>      
      <td>總數量</td>      
	  <?php 
	   $detail = split(";",$value['orderdetail']);
      $count_flag = $value['num'];
      for($i=0;$i<sizeof($detail)-1;$i++)
      {
		//$count = split("-",$detail[$i]);
	    echo "<td>".$dataarray['subtitle'][$i]."</td>";  
        
      }

	  ?>
	  <td>備註</td>


    </tr>
<?php $start++;}  if ($value['oid']!="") { ?>	

    <tr class="odd_row">
      <td><?php echo $value['oid']?></td>
      <td><?php echo $value['order_sn']?></td>
      <td><?php echo $value['gid']?></td>
      <td><?php echo $value['gtitle']?></td>
      <td><?php echo $value['order_total_price']?></td>
      <td><?php echo $value['payment_name']?></td>
      <td><?php echo date("Y-m-d H:i",$value['order_addtime'])?></td>
      <td><?php echo $value['uid']?></td>      
      <td><?php echo $value['uname']?></td>
      <td><?php echo $value['delivery_fee']?></td>            
      <td><?php echo $value['order_weight']?></td>      
      <td><?php echo $value['fname']?></td>      
      <td><?php echo $value['zip']?></td>      
      <td><?php echo $value['address']?></td>      
      <td><?php echo $value['tel']?></td>      
      <td><?php 
       switch ($value['receivetime'])
       {
       	case 0:
        	echo "不指定";
            break;
        case 1:
        	echo "中午前";
            break;
        case 2:
        	echo "12時~17時";
            break;            
         case 3:
         	echo "17時~20時";
            break;
         default:
         	echo "不指定";
            break;          
       }      
      ?></td>
      <td><?php echo $value['num']?></td>

      <?php 
      $detail = split(";",$value['orderdetail']);
      $count_flag = $value['num'];
      for($i=0;$i<sizeof($detail)-1;$i++)
      {
      	$count = split("-",$detail[$i]);
	    echo "<td>".trim($count[1])."</td>";  
        $count_flag -= trim($count[1]);
      }
      
      ?>
		<td>
        <?php if ($count_flag!=0) echo "<font color=red>數據異常,請確認</font>";?>
        </td>
    </tr>
	<?php }}}else{?>
	<tr><td colspan=10>暫無數據..............</td></tr>
	<?php };?>
  </table>
  
